Skip to content

Conversation

@emily-shen
Copy link
Contributor

@emily-shen emily-shen commented Feb 17, 2025

TODO: rebase on /vnext for inclusion in wrangler v4

Might be best to review commit by commit

  • DEVX-1615 improve logging output: d33b18a, 1b0d071
  • DEVX-1611 remove --x-include-runtime and consolidate type output into one file: 2b99075
  • DEVX-1612 prompt users to rerun wrangler types during dev: 4872cb9

This PR will turn on runtime type generation by default for wrangler types.

The --experimental-include-runtime flag will be superseded by include-runtime and include-env, both of which are true by default.

Also, the runtime types will be generated in the same file as the env types, at the location specified by path (worker-configuration.d.ts by default).

Before:
Screenshot 2025-02-19 at 12 09 27

After:
Screenshot 2025-02-18 at 13 42 47


  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • Wrangler E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because: covered by unit tests
  • Public documentation

@changeset-bot
Copy link

changeset-bot bot commented Feb 17, 2025

🦋 Changeset detected

Latest commit: 5eef917

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
wrangler Minor
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Feb 17, 2025

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-wrangler-8166

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/8166/npm-package-wrangler-8166

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-wrangler-8166 dev path/to/script.js
Additional artifacts:

cloudflare-workers-bindings-extension:

wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-cloudflare-workers-bindings-extension-8166 -O ./cloudflare-workers-bindings-extension.0.0.0-ve39885045.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-ve39885045.vsix

create-cloudflare:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-create-cloudflare-8166 --no-auto-update

@cloudflare/kv-asset-handler:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-cloudflare-kv-asset-handler-8166

miniflare:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-miniflare-8166

@cloudflare/pages-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-cloudflare-pages-shared-8166

@cloudflare/unenv-preset:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-cloudflare-unenv-preset-8166

@cloudflare/vite-plugin:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-cloudflare-vite-plugin-8166

@cloudflare/vitest-pool-workers:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-cloudflare-vitest-pool-workers-8166

@cloudflare/workers-editor-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-cloudflare-workers-editor-shared-8166

@cloudflare/workers-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-cloudflare-workers-shared-8166

@cloudflare/workflows-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13639768023/npm-package-cloudflare-workflows-shared-8166

Note that these links will no longer work once the GitHub Actions artifact expires.


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 4.20250214.0-rc.0
workerd 1.20250214.0 1.20250214.0
workerd --version 1.20250214.0 2025-02-14

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@emily-shen emily-shen force-pushed the emily/dynamic-typegen-ga branch from 56b09dc to 3d88fea Compare February 17, 2025 18:05
@emily-shen emily-shen force-pushed the emily/dynamic-typegen-ga branch from 3d88fea to 68d6130 Compare February 18, 2025 12:22
@workers-devprod workers-devprod added the e2e Run wrangler + vite-plugin e2e tests on a PR label Feb 18, 2025
@emily-shen emily-shen force-pushed the emily/dynamic-typegen-ga branch 3 times, most recently from c86cbf3 to 88426fa Compare February 18, 2025 13:42
@emily-shen emily-shen marked this pull request as ready for review February 18, 2025 13:44
@emily-shen emily-shen requested a review from a team as a code owner February 18, 2025 13:44
@@ -0,0 +1,9 @@
---
"wrangler": minor
Copy link
Contributor Author

@emily-shen emily-shen Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

major? pretty sure there's nothing breaking. inclusion in v4 is mostly for politeness as there's a fair amount of CI usage

@emily-shen emily-shen force-pushed the emily/dynamic-typegen-ga branch 4 times, most recently from a7df791 to c931fe0 Compare February 19, 2025 10:31
@emily-shen emily-shen added the v4 label Feb 19, 2025
@emily-shen emily-shen force-pushed the emily/dynamic-typegen-ga branch from 9a873ab to 4872cb9 Compare February 20, 2025 14:23
try {
const { envHeader } = await generateEnvTypes(
config,
{ strictVars: previousStrictVars === "false" ? false : true },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{ strictVars: previousStrictVars === "false" ? false : true },
{ strictVars: previousStrictVars !== "false" },

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the current one as its easier to understand (at least for me)

@emily-shen emily-shen changed the base branch from main to next February 20, 2025 15:22
@emily-shen emily-shen changed the base branch from next to main February 20, 2025 15:23
@emily-shen emily-shen force-pushed the emily/dynamic-typegen-ga branch from 4872cb9 to 2ef9aa4 Compare February 20, 2025 15:24
@vicb
Copy link
Contributor

vicb commented Feb 21, 2025

There's one thing I was thinking about: should we also update the C3 templates?

Currently the worker-configuration.d.ts are static files that only contain interface Env while the cf-typegen scripts will generate both.

Ideally the types should not be in a static file but generated, I have a pending PR that does that for Next.

I think whatever worker-configuration.d.ts contains should match the output of the command. And the best way to do that would be to generate this file (whatever config we decide to use).

If we decide to use the runtime types, tsconfig.json should also be update and we should not install the old types.

/cc @petebacondarwin

@emily-shen
Copy link
Contributor Author

emily-shen commented Feb 21, 2025

There's one thing I was thinking about: should we also update the C3 templates?

I'm actually working on a PR right now to do that :) It'll update C3 to run wrangler types instead of using @cloudflare/workers-types. The plan is to release this in v4, make sure v4 is stable, then bump wrangler in C3 and then add switch over types in C3.

@emily-shen emily-shen changed the base branch from next to main February 27, 2025 14:02
@emily-shen emily-shen force-pushed the emily/dynamic-typegen-ga branch 2 times, most recently from 0e4ca2d to a353f14 Compare February 27, 2025 14:07

Include runtime types in the output of `wrangler types` by default

`wrangler types` will now produce one file that contains both `Env` types and runtime types based on your compatibility date and flags. This is located at `worker-configuration.d.ts` by default.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth taking this opportunity to rename this file, maybe to cloudflare.d.ts? cc @irvinebroque if you have any thoughts here

await ensureDirectoryExists(outFile);

const header = `// Runtime types generated with workerd@${version} ${compatibility_date} ${compatibility_flags.join(",")}`;
const header = `// Runtime types generated with workerd@${version} ${compatibility_date} ${compatibility_flags.sort().join(",")}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is now a combined types file, the header should probably be Types generated with..., which would also bust all existing caches

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#8166 (comment)
also why do we want to bust existing caches?

@penalosa
Copy link
Contributor

Could we have a more unified single header? Something like:

// Generated by Wrangler by running `wrangler types` ([email protected], compatibility_date: 2023-05-04, compatibility_flags: [], env hash: e82ba4d7b995dd9ca6fb0332d81f889b)

{
"compilerOptions": {
...
"types": ${updatedTypesString}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is actually required? It seems to include that file for me by default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh yeah so it does. Is it because its covered by **/*.ts in include??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the default is **/*: https://www.typescriptlang.org/tsconfig/#include

@emily-shen
Copy link
Contributor Author

emily-shen commented Feb 27, 2025

Could we have a more unified single header? Something like:

// Generated by Wrangler by running `wrangler types` ([email protected], compatibility_date: 2023-05-04, compatibility_flags: [], env hash: e82ba4d7b995dd9ca6fb0332d81f889b)

hmm we could, but since we can use cached runtime types independently of env changes, its slightly more convenient to just have that bit on its own line, and i don't think it'll particularly matter to users. happy to change it if you feel strongly about it.

@emily-shen emily-shen requested a review from penalosa February 27, 2025 20:11
Copy link
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple comments, but overall this is looking great!

config,
envInterface,
outputPath
if ((header.length && content.length) || entrypointFormat === "modules") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise this was probably here before, but I don't really understand this logic. Presumably at this stage there will always be something in header & content? What does the entrypointFormat check do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for the extremely niche situation where its a service syntax worker and --include-runtime=false - we don't want to write an empty Env interface for that case.
I have no idea why that would be a problem, but we do have a test making sure we don't... any ideas? 😅


if (envOutOfDate || runtimeOutOfDate) {
logger.log(
"❓ It looks like your types might be out of date. Have you updated your config file since last running `wrangler types`?"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make this more assertive? What's the recommended user action here?

Right now it's not clear what the user should do as a result of their answer to the question posed

const isWorkersTypesInstalled = tsconfigTypes.find((type) =>
type.startsWith("@cloudflare/workers-types")
);
const isNodeTypesInstalled = tsconfigTypes.find((type) => type === "node");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this logic is fully correct. If the types array is empty, but @types/node is in node_modules it'll automatically be picked up as well.

(I realise this is existing logic, but we might as well fix it up)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

600a895 fixed here, but i can't figure out how to test it because the tests always run in a context where @types/nodes exists 😢

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 3, 2025
@emily-shen emily-shen force-pushed the emily/dynamic-typegen-ga branch from 939339f to 600a895 Compare March 3, 2025 20:14
@emily-shen emily-shen changed the base branch from main to next March 3, 2025 20:18
@emily-shen emily-shen merged commit f276a9c into next Mar 4, 2025
24 of 29 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 4, 2025
@emily-shen emily-shen deleted the emily/dynamic-typegen-ga branch March 4, 2025 13:10
penalosa pushed a commit that referenced this pull request Mar 6, 2025
* graduate wrangler type generation to GA

* fixups

* extra changeset
penalosa pushed a commit that referenced this pull request Mar 6, 2025
* graduate wrangler type generation to GA

* fixups

* extra changeset
penalosa pushed a commit that referenced this pull request Mar 7, 2025
* graduate wrangler type generation to GA

* fixups

* extra changeset
penalosa pushed a commit that referenced this pull request Mar 7, 2025
* graduate wrangler type generation to GA

* fixups

* extra changeset
penalosa pushed a commit that referenced this pull request Mar 10, 2025
* graduate wrangler type generation to GA

* fixups

* extra changeset
penalosa pushed a commit that referenced this pull request Mar 11, 2025
* graduate wrangler type generation to GA

* fixups

* extra changeset
penalosa added a commit that referenced this pull request Mar 11, 2025
* ci: setup next branch with prereleases to next tag

* chore: remove deprecated `getBindingsProxy` (#5005)

* Require Node v18 in Wrangler v4 (#7338)

* Remove node_compat in Wrangler & Miniflare v4 (#7336)

* Remove v2 warning (#7228)

* chore: update esbuild (#6884)

* `--local` by default for `wrangler kv` & `wrangler r2` (#7392)

* deprecate unused D1 commands/options  (#7471)

* chore: remove alpha support from `wrangler d1 migrations apply`

* chore: remove `wrangler d1 backups`

* chore: fixup tests

* chore: fixup tests

* chore: fixup tests

* chore: remove --batch-size

* Remove deprecated commands & config (#7352)

* Remove wrangler version

* Remove generate & strip down init

* Add changesets

* Remove deprecated --format & config

* Add changeset

* remove commands

* Fix tests

* Remove .only()

* Remove legacy assets

* clarify legacy assets -> sites naming

* various test fixes after rebase

* fixup! chore: update esbuild (#6884)

esbuild 0.24.2 variable naming changes

* fixup! Remove node_compat in Wrangler & Miniflare v4 (#7336)

* feat(wrangler): Drop worker prefix when creating KV namespaces (#7759)

* feat(wrangler): Drop worker prefix when creating KV namespaces

---------

Co-authored-by: Samuel Macleod <[email protected]>

* Include node version in name

* Ignore kv-asset-handler tests on Node 22

* rename tests

* Rename positional `json` args. Fixes #7688

* unescape

* fix tests

* Update .changeset/funny-pets-punch.md

* Add system requirements to the README

* fix formatting

* fix formatting

* Address feedback

* lockfile

* fix test

* Fix changeset format

* Use RC versioning

* feat: graduate `--x-include-runtime` (#8166)

* graduate wrangler type generation to GA

* fixups

* extra changeset

* Fix legacy assets

* Clarify that node support affects Wrangler & Miniflare & kv-asset-handler

* Clarify comment re node 20

* Add more packages

* Remove obsolete tests

* Rename legacyAssets

* more robust isLocal

* fix test snapshot

* Add --legacy-peer-deps so that installing Wrangler v4 doesn't case issues with frameworks that haven't updated their peer dependency for Wrangler v4

* Remove crypto polyfill

* fix kv.local test after rebase

* fix lockfile

* bump rc version

* revert rc versions

---------

Co-authored-by: Dario Piotrowicz <[email protected]>
Co-authored-by: Max Rozen <[email protected]>
Co-authored-by: Pedro Leal <[email protected]>
Co-authored-by: emily-shen <[email protected]>
gabivlj pushed a commit that referenced this pull request Mar 13, 2025
* ci: setup next branch with prereleases to next tag

* chore: remove deprecated `getBindingsProxy` (#5005)

* Require Node v18 in Wrangler v4 (#7338)

* Remove node_compat in Wrangler & Miniflare v4 (#7336)

* Remove v2 warning (#7228)

* chore: update esbuild (#6884)

* `--local` by default for `wrangler kv` & `wrangler r2` (#7392)

* deprecate unused D1 commands/options  (#7471)

* chore: remove alpha support from `wrangler d1 migrations apply`

* chore: remove `wrangler d1 backups`

* chore: fixup tests

* chore: fixup tests

* chore: fixup tests

* chore: remove --batch-size

* Remove deprecated commands & config (#7352)

* Remove wrangler version

* Remove generate & strip down init

* Add changesets

* Remove deprecated --format & config

* Add changeset

* remove commands

* Fix tests

* Remove .only()

* Remove legacy assets

* clarify legacy assets -> sites naming

* various test fixes after rebase

* fixup! chore: update esbuild (#6884)

esbuild 0.24.2 variable naming changes

* fixup! Remove node_compat in Wrangler & Miniflare v4 (#7336)

* feat(wrangler): Drop worker prefix when creating KV namespaces (#7759)

* feat(wrangler): Drop worker prefix when creating KV namespaces

---------

Co-authored-by: Samuel Macleod <[email protected]>

* Include node version in name

* Ignore kv-asset-handler tests on Node 22

* rename tests

* Rename positional `json` args. Fixes #7688

* unescape

* fix tests

* Update .changeset/funny-pets-punch.md

* Add system requirements to the README

* fix formatting

* fix formatting

* Address feedback

* lockfile

* fix test

* Fix changeset format

* Use RC versioning

* feat: graduate `--x-include-runtime` (#8166)

* graduate wrangler type generation to GA

* fixups

* extra changeset

* Fix legacy assets

* Clarify that node support affects Wrangler & Miniflare & kv-asset-handler

* Clarify comment re node 20

* Add more packages

* Remove obsolete tests

* Rename legacyAssets

* more robust isLocal

* fix test snapshot

* Add --legacy-peer-deps so that installing Wrangler v4 doesn't case issues with frameworks that haven't updated their peer dependency for Wrangler v4

* Remove crypto polyfill

* fix kv.local test after rebase

* fix lockfile

* bump rc version

* revert rc versions

---------

Co-authored-by: Dario Piotrowicz <[email protected]>
Co-authored-by: Max Rozen <[email protected]>
Co-authored-by: Pedro Leal <[email protected]>
Co-authored-by: emily-shen <[email protected]>
gabivlj pushed a commit that referenced this pull request Mar 13, 2025
* ci: setup next branch with prereleases to next tag

* chore: remove deprecated `getBindingsProxy` (#5005)

* Require Node v18 in Wrangler v4 (#7338)

* Remove node_compat in Wrangler & Miniflare v4 (#7336)

* Remove v2 warning (#7228)

* chore: update esbuild (#6884)

* `--local` by default for `wrangler kv` & `wrangler r2` (#7392)

* deprecate unused D1 commands/options  (#7471)

* chore: remove alpha support from `wrangler d1 migrations apply`

* chore: remove `wrangler d1 backups`

* chore: fixup tests

* chore: fixup tests

* chore: fixup tests

* chore: remove --batch-size

* Remove deprecated commands & config (#7352)

* Remove wrangler version

* Remove generate & strip down init

* Add changesets

* Remove deprecated --format & config

* Add changeset

* remove commands

* Fix tests

* Remove .only()

* Remove legacy assets

* clarify legacy assets -> sites naming

* various test fixes after rebase

* fixup! chore: update esbuild (#6884)

esbuild 0.24.2 variable naming changes

* fixup! Remove node_compat in Wrangler & Miniflare v4 (#7336)

* feat(wrangler): Drop worker prefix when creating KV namespaces (#7759)

* feat(wrangler): Drop worker prefix when creating KV namespaces

---------

Co-authored-by: Samuel Macleod <[email protected]>

* Include node version in name

* Ignore kv-asset-handler tests on Node 22

* rename tests

* Rename positional `json` args. Fixes #7688

* unescape

* fix tests

* Update .changeset/funny-pets-punch.md

* Add system requirements to the README

* fix formatting

* fix formatting

* Address feedback

* lockfile

* fix test

* Fix changeset format

* Use RC versioning

* feat: graduate `--x-include-runtime` (#8166)

* graduate wrangler type generation to GA

* fixups

* extra changeset

* Fix legacy assets

* Clarify that node support affects Wrangler & Miniflare & kv-asset-handler

* Clarify comment re node 20

* Add more packages

* Remove obsolete tests

* Rename legacyAssets

* more robust isLocal

* fix test snapshot

* Add --legacy-peer-deps so that installing Wrangler v4 doesn't case issues with frameworks that haven't updated their peer dependency for Wrangler v4

* Remove crypto polyfill

* fix kv.local test after rebase

* fix lockfile

* bump rc version

* revert rc versions

---------

Co-authored-by: Dario Piotrowicz <[email protected]>
Co-authored-by: Max Rozen <[email protected]>
Co-authored-by: Pedro Leal <[email protected]>
Co-authored-by: emily-shen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c3-e2e Run c3 e2e tests on a PR e2e Run wrangler + vite-plugin e2e tests on a PR

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants